let validPhone = (rule, value, callback) => {
    let isvalidPhone = (str) => {
      const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
      return reg.test(str)
    }
    if (!value) {
      callback(new Error('请输入手机号码'))
    } else if (!isvalidPhone(value)) {
      callback(new Error('请输入正确的11位手机号码'))
    } else {
      callback()
    }
  }
  let validTel = (rule, value, callback) => {
    let isvalidPhone = (str) => {
      const reg = /^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$/
      return reg.test(str)
    }
    if (!value) {
      callback(new Error('请输入电话号码'))
    } else if (!isvalidPhone(value)) {
      callback(new Error('请输入正确的电话号码'))
    } else {
      callback()
    }
  }
  let validIdCard = (rule, value, callback) => {
    let isvalidPhone = (str) => {
      const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
      return reg.test(str)
    }
    if (!value) {
      callback(new Error('请输入身份证号码'))
    } else if (!isvalidPhone(value)) {
      callback(new Error('请输入正确的身份证号码'))
    } else {
      callback()
    }
  }
  
  let checkIntegerNumber = (rule, value, callback) => {
    let reg = /^[1-9]\d{0,5}?$/
    if (!value) {
      callback(new Error('请输入数字'))
    }
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入最大6位整数'))
    }
  }
  // 验证数字非必选
  let checkNotIntegerNumber = (rule, value, callback) => {
    let reg = /^[1-9]\d{0,5}?$/
    if (value === '') {
      callback()
    }
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入最大6位整数'))
    }
  }
  let carNumber = (rule, value, callback) => {
    let xreg8 = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/
    if (value.length > 6) {
      if (xreg8.test(value)) {
        callback()
      } else {
        callback(new Error('请输入正确的车牌号码(字母请大写)'))
      }
    } else {
      callback(new Error('请输入正确的车牌号码(字母请大写)'))
    }
  }
  let checkCurrencyNumber = (rule, value, callback) => {
    let reg = /^(?:0|[1-9]\d{0,2})(?:\.\d{1,2})?$/
    if (!value) {
      callback(new Error('请输入数字'))
    }
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入最大999.99的数字'))
    }
  }
  let checkCurrencyNumbers = (rule, value, callback) => {
    let reg = /^(?:0|[1-9]\d{0,7})(?:\.\d{1,2})?$/
    if (!value) {
      callback(new Error('请输入数字'))
    }
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入最大99999999.99的数字'))
    }
  }
  
  const rulesMain = {
    phone: validPhone,
    tel: validTel,
    idCard: validIdCard,
    checkIntegerNumber: checkIntegerNumber,
    checkNotIntegerNumber: checkNotIntegerNumber,
    carNumber: carNumber,
    checkCurrencyNumber: checkCurrencyNumber,
    checkCurrencyNumbers:checkCurrencyNumbers
  }
  
  export default rulesMain